<template>
  <el-dialog :title="title"
             :visible.sync="dialogVisible"
             class="book-dialog"
             width="750px"
             :close-on-click-modal="false">
    <el-form ref="dialogForm"
             :model="form"
             label-width="120px"
             :rules="rules">
      <el-form-item label="文档名"
                    prop="name">
        <el-input v-model="form.name"
                  clearable
                  autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="上传封面"
                    prop="image">
        <image-input type="cover"
                     v-model="form.image"></image-input>
        <span style="color: #999;">注：建议上传尺寸60*60的 PNG图</span>
      </el-form-item>
      <el-form-item label="简介"
                    prop="desc">
        <el-input v-model="form.desc"
                  autocomplete="off"
                  clearable
                  type="textarea"
                  :rows="4"></el-input>
      </el-form-item>
      <el-form-item label="是否显示">
        <el-switch v-model="form.status"
                   active-text="显示"
                   :active-value="1"
                   :inactive-value="0">
        </el-switch>
      </el-form-item>
    </el-form>
    <div slot="footer"
         class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary"
                 @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import imageInput from '@/components/image-input'

export default {
  name: "index",
  data () {
    return {
      dialogVisible: false,
      form: {
        name: undefined,
        images: [],
        desc: undefined,
        status: 1
      },
      rules: {
        name: [
          { required: true, message: '名称不能为空' }
        ],
        image: [
          { required: true, message: '封面不能为空' }
        ],
      }
    }
  },
  components: {
    imageInput
  },
  computed: {
    title () {
      return '新增文档'
    }
  },
  methods: {
    open () {
      this.dialogVisible = true
      return new Promise((resolve) => {
        this._resolve = resolve
      })
    },
    close () {
      this.dialogVisible = false
    },
    submit () {
    }
  }
}
</script>

<style scoped lang="scss">
.book-dialog {
  text-align: left;
}
.el-form {
  width: 600px;
}
.dialog-footer {
  text-align: center;
}
</style>
